package middleware

import (
	"strconv"

	"github.com/gin-gonic/gin"

	"collecter/app/common/enum"
	"collecter/app/common/helper"
	"collecter/app/controller"
)

func Common() gin.HandlerFunc {
	fn := func(ctx *gin.Context) {
		ctx.Header("Content-Type", "application/json;charset=utf-8")
		serverName := helper.Configer.GetString("serverName")
		if len(serverName) > 0 {
			ctx.Header("server", serverName)
		}

		// 控制器基类中 Ctx 变量赋值
		controller.Ctx = ctx
		controller.Page, _ = strconv.Atoi(ctx.DefaultQuery("page", "1"))
		controller.Limit, _ = strconv.Atoi(ctx.DefaultQuery("limit", strconv.Itoa(enum.DEFAULT_LIMIT)))

	}
	return fn
}
